(function () {
    //{if $prev}//var appid = 'wx2054bed22814a315',secret = '77305888f781790605ca7f1fd2eceaf6',
    //{else}//
    var appid = 'wx0e1c69a45f2a6c5c',
        secret = '5bb03649bf848c4b398f1ef4e7ea69b9',
    //{/if}//
        openid = localStorage.getItem('openId'),
        core = ecui,
        util = core.util,
        dom = ecui.dom;

    ecui.util.extend(NS.ui, {
        Logout: ecui.inherits(
            ecui.ui.Control,
            {
                onclick: function () {
                    if (mao.info.isDingTalk) {
                        delete mao.info.userId;
                        dd.util.domainStorage.removeItem({ name:'openId' });
                        window.localStorage.removeItem('openId');
                        dd.util.domainStorage.removeItem({ name:'userId' });
                        window.localStorage.removeItem('userId');
                        window.location.reload();
                    } else if (mao.info.isWeixin) {
                        ecui.esr.request(
                            'data@JSON /erp-management/unbind/account?openId=' + openid,
                            function () {
                                var data = ecui.esr.getData('data');
                                if (data instanceof Object) {
                                    location.href = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=' + appid + '&redirect_uri=http%3A%2F%2Fu.mao-livehouse.com/maolive-app/bind.html&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect';
                                }
                            },
                            function () {
                                return false;
                            }
                        );
                    } else {
                        window.localStorage.removeItem('openId');
                        window.localStorage.removeItem('userId');
                        window.location.reload();
                    }
                }
            }
        ),
        HeadChange: ecui.inherits(
            mao.ui.ImageAdd,
            {
                onupload: function (res) {
                    res = JSON.parse(res);
                    this._eFile.value = ''; // 解决连续操作上传删除同一张图片时，第二次上传失败问题
                    if (res.code === 0) { // 显示上传的图片
                        this._eImg.src = res.data.imageUrl || this._sDefaultImg;
                        ecui.esr.request(
                            'data@JSON /erp-management/staff/update/head-portrait?id=' + res.data.id,
                            function () {
                                var data = ecui.esr.getData('data');
                                if (data instanceof Object) {
                                    ecui.tip('warn', '修改成功');
                                }
                            },
                            function () {

                            }
                        );
                        this._eInput.value = res.data.id;
                    } else if (res.code === 12020) {
                        ecui.tip('warn', '最大支持10m图片，请重新选择');
                    }
                }
            }
        )
    });
    ecui.esr.addRoute('me', {
        model: [
            // 'detail@GET /erp-management/venue/order/${orderSn}'
        ],
        weight: 1,
        main: 'nav_tab_me',
        view: 'me',
        frame: true,
        onbeforerequest: function (context) {

        },
        onbeforerender: function (context) {
            context.roleNames = mao.staffInfo.roleList.map(function (item) { return item.name; }).join(',');
            context.venueNames = mao.staffInfo.venueList.map(function (item) { return item.name; }).join(',');
        }
    });
}());